package com.owc.controller.app;

import com.owc.common.custom.annotation.Advice;
import com.owc.domain.BaseResult;
import com.owc.domain.PageBean;
import com.owc.domain.PageVo;
import com.owc.domain.dto.ExchangeBaseDTO;
import com.owc.domain.dto.admin.RateConfigDTO;
import com.owc.domain.dto.admin.SystemConfigDTO;
import com.owc.domain.entity.SystemConfig;
import com.owc.domain.vo.app.ExchangeVo;
import com.owc.filter.content.SecurityContextHolder;
import com.owc.service.app.ExchangeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * @Author xiaom
 * @Date 2020/2/27 14:04
 * @Version 1.0.0
 * @Description <>
 **/
@RestController
@RequestMapping("/exchange")
@Api(tags = "(APP-V2)兑换管理")
public class ExchangeController {

    @Autowired
    private ExchangeService exchangeService;

    @PostMapping(value = "/to")
    @ApiOperation("发起兑换")
    public BaseResult<Boolean> exchange(@RequestBody @Valid ExchangeVo exchangeVo) throws Exception {
        return BaseResult.success(exchangeService.exchange(exchangeVo));
    }

    @PostMapping(value = "/getRateConfig")
    @ApiOperation("获取汇率配置")
    public BaseResult<List<RateConfigDTO>> getRateConfig(){
        return BaseResult.success(exchangeService.getRateConfig());
    }

    @PostMapping(value = "/getExchangeRecord")
    @ApiOperation("获取兑换记录")
    public BaseResult<PageBean<ExchangeBaseDTO>> getExchangeRecord(@RequestBody PageVo pageVo){
        return BaseResult.success(exchangeService.getExchangeRecord(pageVo.getPageIndex(),pageVo.getPageSize()));
    }

}
